package com.zhiche.lisa.bms.controller.sta;


import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.bms.dao.model.quote.Quote;
import com.zhiche.lisa.bms.dao.model.sta.StaPrice;
import com.zhiche.lisa.bms.pojo.vo.common.CommonVO;
import com.zhiche.lisa.bms.pojo.vo.sta.StaPriceAndQuoteDtlVO;
import com.zhiche.lisa.bms.service.sta.StaPriceService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标准价同步表 前端控制器
 * </p>
 *
 * @author liuanshun
 * @since 2018-10-23
 */
@RestController
@RequestMapping("/staPrice")
@Api(value = "/staPrice", description = "标准价同步接口", tags = {"标准价同步接口"})
public class StaPriceController {
    private final Logger LOGGER = LoggerFactory.getLogger(StaPriceController.class);
    @Autowired
    private StaPriceService staPriceService;

    @PostMapping(value = "/getStaPricePage")
    @ApiOperation(value = "根据条件查询同步价格信息", notes = "根据条件查询同步价格信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Quote.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<Page<StaPrice>> getStaPricePage(@RequestBody Page<StaPrice> page) {
        LOGGER.info("/StaPriceController.getStaPricePage Param {} ", page);
        RestfulResponse<Page<StaPrice>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            Page<StaPrice> quotePage = staPriceService.selectStaPricePage(page);
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.getStaPricePage ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.getStaPricePage ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }

    @PostMapping(value = "/getStaPriceList")
    @ApiOperation(value = "根据条件查询同步价格信息", notes = "根据条件查询同步价格信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Quote.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<StaPrice>> getStaPriceList(@RequestBody Map<String, Object> condition) {
        LOGGER.info("/StaPriceController.getStaPriceList Param {} ", condition);
        RestfulResponse<List<StaPrice>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<StaPrice> quotePage = staPriceService.selectStaPriceList(condition);
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.getStaPriceList ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.getStaPriceList ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }

    @PostMapping(value = "/getStaPriceListByProperty")
    @ApiOperation(value = "根据属性值匹配同步价格信息", notes = "根据属性值匹配同步价格信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success", response = Quote.class), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<StaPriceAndQuoteDtlVO>> getStaPriceListByProperty(@RequestBody CommonVO<StaPriceAndQuoteDtlVO> staPrices) {
        LOGGER.info("/StaPriceController.getStaPriceListByProperty Param {} ", staPrices);
        RestfulResponse<List<StaPriceAndQuoteDtlVO>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<StaPriceAndQuoteDtlVO> quotePage = staPriceService.selectStaPriceVOListByProperty(staPrices.getEntityParams(), staPrices.getCondition());
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.getStaPriceListByProperty ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.getStaPriceListByProperty ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }

    @GetMapping(value = "/selectAllTransportNodeGid")
    @ApiOperation(value = "获取全部车型", notes = "获取全部车型", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Object>> selectAllTransportNodeGid() {
        LOGGER.info("/StaPriceController.selectAllTransportNodeGid Param {} ");
        RestfulResponse<List<Object>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<Object> quotePage = staPriceService.selectAllStaPriceTransportNodeGid();
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.selectAllTransportNodeGid ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.selectAllTransportNodeGid ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }

    @GetMapping(value = "/selectAllproperty")
    @ApiOperation(value = "获取全部车型", notes = "获取全部车型", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Object>> selectAllproperty(@RequestParam String type) {
        LOGGER.info("/StaPriceController.selectAllproperty Param {} ", type);
        RestfulResponse<List<Object>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<Object> quotePage = staPriceService.selectAllProperty(type);
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.selectAllproperty ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.selectAllproperty ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }

    @GetMapping(value = "/selectAllStaPriceStartLoctionName")
    @ApiOperation(value = "获取全部起运地", notes = "获取全部起运地", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<List<Object>> selectAllStaPriceStartLoctionName() {
        LOGGER.info("/StaPriceController.selectAllStaPriceStartLoctionName Param {} ");
        RestfulResponse<List<Object>> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            List<Object> quotePage = staPriceService.selectAllStaPriceStartLoctionName();
            restful.setData(quotePage);
        } catch (BaseException e) {
            LOGGER.error("/StaPriceController.selectAllStaPriceStartLoctionName ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/StaPriceController.selectAllStaPriceStartLoctionName ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }
}

